package com.chorye.concurrent.controller;

import com.chorye.concurrent.entity.StudentThird;
import com.chorye.concurrent.service.StudentThirdService;
import com.croot.ta.rest.RespCode;
import com.croot.ta.rest.Response;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Chorye
 * @since 2019-06-27
 */
@RestController
@RequestMapping("/studentThird")
public class StudentThirdController {

    /**
     * 日志记录
     */
    private final Logger logger = LoggerFactory.getLogger(StudentThirdController.class);

    /**
     * 服务层注入
     */
    @Autowired
    public StudentThirdService studentThirdService;

    /**
     * 查询所有记录
     *
     * @return 列表所有数据
     */
    @ApiOperation(value = "请填写", notes = "列表接口")
    @GetMapping(value = {"/list"})
    public Response list() {
        return new Response(RespCode.SUCCESS, studentThirdService.list(null));
    }

    /**
     * 根据主键查询一条记录
     *
     * @param id 唯一标识
     * @return 列表所有数据
     */
    @ApiOperation(value = "请填写", notes = "列表接口")
    @GetMapping(value = {"/studentThird/{id}"})
    public Response list(@PathVariable String id) {
        return new Response(RespCode.SUCCESS, studentThirdService.getById(id));
    }

    /**
     * 新增
     *
     * @param studentThird 实体类
     * @return 成功标识
     */
    @ApiOperation(value = "请填写", notes = "新增接口")
    @PostMapping(value = "/save")
    public Response save(StudentThird studentThird) {
        // 插入后返回true则返回成功，否则返回失败
        if (studentThirdService.save(studentThird)) {
            return new Response(RespCode.SUCCESS);
        }
        logger.debug("新增记录 {} 失败", studentThird);
        return new Response(RespCode.FAILURE);
    }

    /**
     * 通过Id修改
     *
     * @param studentThird 实体类
     * @return 成功标识
     */
    @ApiOperation(value = "请填写", notes = "修改接口")
    @PostMapping(value = "/update")
    public Response update(StudentThird studentThird) {
        // 修改后返回true则返回成功，否则返回失败
        if (studentThirdService.updateById(studentThird)) {
            return new Response(RespCode.SUCCESS);
        }
        logger.debug("修改记录 {} 失败", studentThird);
        return new Response(RespCode.FAILURE);
    }

    /**
     * 通过Id删除
     *
     * @param id 唯一标识
     * @return 成功标识
     */
    @ApiOperation(value = "请填写", notes = "删除接口")
    @PostMapping(value = "/delete")
    public Response delete(String id) {
        // 插入后返回true则返回成功，否则返回失败
        if (studentThirdService.removeById(id)) {
            return new Response(RespCode.SUCCESS);
        }
        logger.debug("删除记录 {} 失败", id);
        return new Response(RespCode.FAILURE);
    }
}
